//ToDo: create cartouche
var position2 = 0;

$(document).ready(function(e) {
	$('.abc').show();
	//create animate function for abc
	$('.abc .head').live('click', function () {
		$abc = $(this).parent();
		if ($abc.hasClass('opened')) {
			$abc.find('.content').eq(0)
			.animate({height:"+=5px"},100).animate({
				height: '5px'
			}, 200, function () { 
					$abc.css('bottom', ($('.abc .head').height()/2)-$('.abc .head').height());
					$abc.removeClass('opened'); 
					$(this).find('ul').hide(); 
			});
		}
		else {
			$abc.find('.content').eq(0)
			.animate({
				height: '25px'
			}, 200, function () { 
					$abc.css('bottom', (25-$('.abc .head').height()));
					$abc.addClass('opened');
					$(this).find('ul').show(); 
			}).animate({height:"-=5px"},100);
		}
	});
	
	
	// scrolling abc element
	$('.abc .content img').live('click', function () {
		oldposition = position2;
		
		if ($(this).hasClass('abc-left')) {
			position2-= $('.alpha').width();
		}
		else {
			position2+= $('.alpha').width();
		}
		
		if (position2 >= 0 && position2 <= $('.alpha')[0].scrollWidth) {
			$('.alpha').animate({scrollLeft: position2});
		}
		else {
			position2 = oldposition;
		}
	});
	
	// click on abc element
	$('.abc .content li').live('click', function (e) {
		if ($('#ihm-content-listing').attr('old-query') && !$(this).hasClass('selected')) {
			$element = $(this);
			_url = $('#ihm-content-listing').attr('old-query').split('/abc/');
			_url = _url[0] + '/abc/' + $element.html();
			$.ajax({
			   url: _url,
			   beforeSend: function () {
					wait_block('ihm-content-listing', JAVASCRIPT_WAIT);
			   },
			   success: function (message, status) {
			    	if (message != $('#ihm-content-listing').html()) {
						$('#ihm-content-listing').html(message);
					}
			   },
			   complete: function () {
				   $element.parent().find('li').removeClass('selected');
				   $element.addClass('selected');
				   $('#ihm-content-listing').attr('old-query', _url);
				   _scrollbar();
				   $("#ihm-content .content").css({top:0});
				   stop = false;
			   }
			});
		}
	});
	
	// cancel filter
	$('.abc .content li.selected').live('dblclick', function (e) {
		$element = $(this);
		_url = $('#ihm-content-listing').attr('old-query').split('/abc/');
		_url = _url[0];
		$.ajax({
		   url: _url,
		   beforeSend: function () {
				wait_block('ihm-content-listing', JAVASCRIPT_WAIT);
		   },
		   success: function (message, status) {
		    	if (message != $('#ihm-content-listing').html()) {
					$('#ihm-content-listing').html(message);
				}
		   },
		   complete: function () {
			   $element.removeClass('selected');
			   $('#ihm-content-listing').attr('old-query', _url);
			   $element.blur();
			   _scrollbar();
			   $("#ihm-content .content").css({top:0});
			   stop = false;
		   }
		});
	});
	
});